package com.company;
import java.util.Scanner;

public class HJ5 {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            int res=0;
            String tmp=in.nextLine();
            int k=0;
            for(int i=tmp.length()-1;i>1;i--){
                if(Character.isLetter(tmp.charAt(i))){
                    res+=(tmp.charAt(i)-'A'+10)*Math.pow(16,k);
                }else{
                    res+=(tmp.charAt(i)-'0')*Math.pow(16,k);
                }
                k++;
            }
            System.out.println(res);
        }
    }
}
